package com.tj.jinzao.base;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * BaseAdapter基类
 * Created by wjy on 2015/7/16.
 */
public abstract class BaseCommonAdapter<T> extends BaseAdapter {
    protected final LayoutInflater mInflater;

    protected int mLoadingBitmapResId, mItemLayoutId;

    protected List<T> mList;

    public int mWidth, mHeight;
    protected int mImageWidth, mImageHeight;
    protected Context mContext;

    public final static String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public BaseCommonAdapter(Context context, List<T> list, int itemLayoutId) {
        this.mContext = context;
        this.mInflater = LayoutInflater.from(mContext);
        this.mList = list;
        this.mItemLayoutId = itemLayoutId;
    }

    public final int getWidth() {
        return mWidth;
    }

    public final int getHeight() {
        return mHeight;
    }

    @Override
    public int getCount() {
        return mList != null ? mList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        if (mList != null && position < mList.size() && position > -1) {
            return mList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = getConvertView(position);
        }
        bindViewData(convertView, position);
        return convertView;
    }

    protected abstract View getConvertView(int position);

    protected abstract void bindViewData(View convertView, int position);

}
